package vincent.com.layouttest;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.EditText;

import vincent.com.layouttest.view.BrokenLineChartView;

/**
 * Created by chenzhengwen on 2015/6/8.
 */
public class BrokenLineChartActivity extends ActionBarActivity implements View.OnClickListener{
    private BrokenLineChartView brokenLineChart;

    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch(msg.what){
                case 1:
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broken_line_chart);

        brokenLineChart = (BrokenLineChartView)findViewById(R.id.broken_line_chart_view);

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        final ViewTreeObserver observer = brokenLineChart.getViewTreeObserver();
        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                drawLines();
                brokenLineChart.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){

        }
    }

    public void drawLines(){

        float[] pointers = new float[8];
        pointers[0] = 10;
        pointers[1] = 10 * 5;
        pointers[2] = 20;
        pointers[3] = 20 * 5;
        pointers[4] = 30;
        pointers[5] = 40 * 5;
        pointers[6] = 40;
        pointers[7] = 20 * 5;

        /*float[] pointers = new float[16];
        for(int i = 0; i < pointers.length; i+=2){
            pointers[i] = i * 20;
            pointers[i+1] = brokenLineChart.getHeight() - i * 20;
        }*/

        brokenLineChart.setPointers(pointers);
    }
}
